package com.augurit.common.system.service.org.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;

import com.augurit.common.dao.AtServerConvertDao;
import com.augurit.common.entity.AtServerConvert;
import com.augurit.common.system.service.org.IAtServerConvertService;
import com.augurit.common.system.web.org.form.AtServerConvertForm;
import com.augurit.common.util.PageUtils;

/**
 * WEB服务器外网地址转换逻辑实现类
 */
@Service
@Transactional
public class AtServerConvertServiceImpl implements IAtServerConvertService {
	
	// DAO 引用
	@Autowired
	private AtServerConvertDao atServerConvertDao; //应用DAO类

	
	/**
	 * 根据ID获取业务字典项Form对象
	 * @param id 业务字典项主键ID
	 * @return 业务字典项Form对象
	 */
	@Transactional(readOnly = true)
	public AtServerConvertForm get(Long id){
		return atServerConvertDao.getForm(id);
	}

	/**
	 * 保存业务字典项Form对象
	 * @param form Form对象
	 */
	public void save(AtServerConvertForm form){
		atServerConvertDao.save(form);
	}
	
	/**
	 * 保存业务字典项Form对象数组
	 * @param forms Form对象数组
	 */
	public void save(AtServerConvertForm[] forms){
		if(forms != null && forms.length > 0){
			for(AtServerConvertForm form : forms)
				atServerConvertDao.save(form);
		}
	}

	public void save(List<AtServerConvertForm> forms){
		if(forms != null && forms.size() > 0){
			for(AtServerConvertForm form : forms)
				atServerConvertDao.save(form);
		}
	}
	
	/**
	 * 根据主键ID删除业务字典项对象
	 * @param id 业务字典项对象主键ID
	 */
	public void delete(Long id) {
		if(id != null)
			atServerConvertDao.delete(id);
	}
	
	/**
	 * 根据主键ID集合删除多个业务字典项对象
	 * @param ids 业务字典项主键ID集合
	 */
	public void delete(Long[] ids) {
		if(ids != null && ids.length > 0)
			atServerConvertDao.delete(ids);
	}

	/**
	 * 分页获取所有对象
	 * @param page
	 * @return
	 */
	@Transactional(readOnly = true)
	public Page<AtServerConvertForm> getAll(Page<AtServerConvertForm> page){
		// 建立新的分页对象
		Page<AtServerConvert> pg = PageUtils.newPageInstance(page);
		
		// 查询语句及参数
		String hql = "from AtServerConvert ps order by ps.isActive desc";
		atServerConvertDao.findPage(pg, hql);
		
		// 转换为Form对象列表并赋值到原分页对象中
//		List<AtServerConvertForm> list = DozerUtils.map(pg.getResult(), AtServerConvertForm.class);
//		PageUtils.copy(pg, list, page);
		return page;
	}
}
